﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Web;
using System.Web.Mvc;
using XinYue.Permission.BLL;
using XinYue.Permission.Mode;
using XinYue.Permission.Web.Models;

namespace XinYue.Permission.Web.Controllers
{
    public class HomeController : Controller
    {
        MenuService menuService = new MenuService();
        public ActionResult Role()
        {
            return View();
        }
        public ActionResult Module()
        {
            return View();
        }
        public ActionResult Role_Add()
        {
            return View();
        }
        public ActionResult Function()
        {
            #region 功能管理-下拉框查询
            Expression<Func<Menu, bool>> OrderBylambda = a => a.ParentId > 0;
            List<Menu> list = menuService.QueryList(OrderBylambda);
            ViewBag.list = list;
            #endregion
            return View();
        }
        public ActionResult Function_Add()
        {
            return View();
        }
        public ActionResult Index()
        {
            return View();
        }
        public ActionResult Menu()
        {
            return View();
        }
        public ActionResult Menu_Add()
        {
            return View();
        }
        public ActionResult Category_Manage()
        {
            return View();
        }
        public ActionResult ProductCategoryAdd(string ID)
        {
            return View();
        }
       
        public ActionResult LoginBack()
        {
            return View();
        }
        public ActionResult Admin_info()
        {
            return View();
        }
        public ActionResult Admin_Competence()
        {
            return View();
        }
        public ActionResult System_section()
        {
            return View();
        }
        public ActionResult Competence()
        {
            //创建菜单业务层对象
            MenuService roleService = new MenuService();
            //定义查询父类菜单集合拉姆达表达式
            Expression<Func<Menu, bool>> parentLambda = a => a.ParentId == 0;
            //接收父类List集合
            ViewBag.parentList = roleService.QueryList(parentLambda);
            //定义查询子类菜单集合拉姆达表达式
            Expression<Func<Menu, bool>> sonLambda = a => a.ParentId != 0;
            //接收子类List集合
            ViewBag.sonList = roleService.QueryList(sonLambda);
            //定义查询功能集合拉姆达表达式
            Expression<Func<Function, bool>> functionLambda = a => a.MenuId != 0;
            //创建功能业务层对象
            FunctionListService functionService = new FunctionListService();
            //接收功能List集合
            ViewBag.functionList = functionService.QueryList(functionLambda);
            //创建组业务层对象
            ModuleService moduleService = new ModuleService();
            //定义查询组集合的拉姆达表达式
            Expression<Func<Module, bool>> moduleLambda = a => a.Id != 0;
            //接收组列表集合
            ViewBag.moduleList = moduleService.QueryList(moduleLambda);
            return View();
        }
        public ActionResult Administrator()
        {
            //获取所有组
            ModuleService moduleService = new ModuleService();
            Expression<Func<Module, bool>> WhereModule = c => true;
            ViewBag.Module = moduleService.QueryList(WhereModule);
            //获取所有角色
            RoleNameService roleNameService = new RoleNameService();
            Expression<Func<Role, bool>> WhereRole = c => true;
            ViewBag.Role = roleNameService.QueryList(WhereRole);
            return View();
        }
        //修改权限页面
        public ActionResult UpdateCompetence(int id)
        {
            //定义角色菜单功能关联表业务层对象
            BaseService<RoleFunctionPermission> service = new BaseService<RoleFunctionPermission>();
            //定义查询角色菜单功能关联表集合拉姆达表达式
            Expression<Func<RoleFunctionPermission, bool>> roleFunctionLambda = a => a.RoleId == id;
            //接收集合
            ViewBag.roleFunctionList = service.QueryList(roleFunctionLambda);
            //创建角色业务层对象
            RoleService roleService = new RoleService();
            //定义查询角色表对象拉姆达表达式
            Expression<Func<Role, bool>> roleLambda = a => a.Id == id;
            //接收对象
            ViewBag.role = roleService.Query(roleLambda);
            //创建角色和组关联业务层
            BaseService<ModuleRole> baseService = new BaseService<ModuleRole>();
            //定义查询角色和组关联表对象拉姆达表达式
            Expression<Func<ModuleRole, bool>> moduleRoleLambda = a => a.RoleId == id;
            //接收对象
            ViewBag.moduleRole = baseService.Query(moduleRoleLambda);
            //创建菜单业务层对象
            MenuService menuService = new MenuService();
            //定义查询父类菜单集合拉姆达表达式
            Expression<Func<Menu, bool>> parentLambda = a => a.ParentId == 0;
            //接收父类List集合
            ViewBag.parentList = menuService.QueryList(parentLambda);
            //定义查询子类菜单集合拉姆达表达式
            Expression<Func<Menu, bool>> sonLambda = a => a.ParentId != 0;
            //接收子类List集合
            ViewBag.sonList = menuService.QueryList(sonLambda);
            //定义查询功能集合拉姆达表达式
            Expression<Func<Function, bool>> functionLambda = a => a.MenuId != 0;
            //创建功能业务层对象
            FunctionListService functionService = new FunctionListService();
            //接收功能List集合
            ViewBag.functionList = functionService.QueryList(functionLambda);
            //创建组业务层对象
            ModuleService moduleService = new ModuleService();
            //定义查询组集合的拉姆达表达式
            Expression<Func<Module, bool>> moduleLambda = a => a.Id != 0;
            //接收组列表集合
            ViewBag.moduleList = moduleService.QueryList(moduleLambda);
            return View();
        }
       
    }
}